package cn.tutu.blockchain.cktuser.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tutu.blockchain.cktuser.dao.CktUserDao;
import cn.tutu.blockchain.cktuser.entity.CktUser;
import cn.tutu.blockchain.cktuser.service.CktUserService;
import cn.tutu.blockchain.exception.BusinessException;
import cn.tutu.blockchain.sysuser.dao.SysUserDao;
import cn.tutu.blockchain.sysuser.entity.SysUser;

@Service
public class CktUserServiceImpl implements CktUserService{
	
	@Autowired
	private CktUserDao ctkUserDao;
	
	@Autowired
	private SysUserDao sysUserDao;

	@Override
	public void create(String phone, String ethId) {
		SysUser sysUser = sysUserDao.findByPhone(phone);
		if(null == sysUser) {
			throw new BusinessException(phone + "用户不存在");
		}
		
		CktUser cktUser = new CktUser();
		cktUser.setUserId(sysUser.getId());
		cktUser.setCktId(ethId);
		List<CktUser> cktUserList = ctkUserDao.findByModel(cktUser);
		if(null != cktUserList && cktUserList.size()>0) {
			throw new BusinessException("该用户与ckt帐户已绑定过,无需再次设置");
		}
		ctkUserDao.insert(cktUser);
		
	}

	@Override
	public List<CktUser> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

}
